package com.dongdongmovie.controller;

import com.dongdongmovie.pojo.AdminUser;
import com.dongdongmovie.pojo.Resources;
import com.dongdongmovie.service.Resource_Service;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("Resources")
public class Resources_Controller {

    //注入service
    @DubboReference
    private Resource_Service resource_service;

    //跳转到主页
    @RequestMapping("tzresource")
    public String tzresource() {
        return "Resource/resource";
    }

    //跳转到show
    @RequestMapping("tzshow")
    public String tzshow() {
        return "Resource/show";
    }

    //跳转到add
    @RequestMapping("tzadd")
    public String tzadd() {
        return "Resource/add";
    }

    //跳转到update
    @RequestMapping("tzupdate")
    public String tzupdate(Integer resId, Model m) {
        Resources r = resource_service.showbyId(resId);
        m.addAttribute("r", r);
        return "Resource/update";
    }

    //查询主页tree
    @ResponseBody
    @RequestMapping("show")
    public List<Map<String, Object>> show(HttpServletRequest request) {
        AdminUser a = (AdminUser)request.getSession().getAttribute("AdminUser");
        List<Map<String, Object>> show = resource_service.show(a);
        return show;
    }

    //查询主页ztree
    @ResponseBody
    @RequestMapping("showresource")
    public List<Map<String, Object>> showresource() {
        return resource_service.showresource();
    }

    //查询主页ztree(角色修改用)
    @ResponseBody
    @RequestMapping("showresources")
    public List<Map<String, Object>> showresources(Integer roleId) {
        return resource_service.showresources(roleId);
    }

    //添加数据
    @ResponseBody
    @RequestMapping("add")
    public int add(Resources r) {
        return resource_service.add(r);
    }

    //修改数据
    @ResponseBody
    @RequestMapping("update")
    public int update(Resources r) {
        return resource_service.update(r);
    }

    //根据id删除
    @ResponseBody
    @RequestMapping("delete")
    public int delete(Integer resId) {
        return resource_service.delete(resId);
    }

}
